import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router'
import Layout from '@/layout/index.vue'
import Cate from '@/views/Cate/index.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path:'/',
    name:'Layout',
    component:Layout,
    children:[{
      path:'/',
      name:'home',
      component:()=>import('@/views/Home/index.vue')
    },{
      path:'/category/:cateId',
      name:'category',
      component:Cate
    },{
      path:'/detail/:articleId',
      component: () => import('@/views/Detail/index.vue'),
      name:"Detail"
    },{
      path:'/archive',
      component: () => import('@/views/Archive/index.vue'),
      name:"Archive"
    },{
      path:'/tag',
      component: () => import('@/views/Tag/index.vue'),
      name:"Tag"
    },{
      path:'/friend',
      component: () => import('@/views/FriendLink/index.vue'),
      name:"FriendLink"
    },]
  },{ path: "/:catchAll(.*)",component:() => import('@/components/404/404.vue') }
]

// https://juejin.cn/post/7253062314306322491掘金文章


const router = createRouter({
  history:  process.env.NODE_ENV === 'production' ? createWebHistory() : createWebHashHistory(),
  routes
})


router.beforeEach((to,from,next) => {
  document.title = process.env.VUE_APP_TITLE
  next()
})

export default router
